﻿using System.Linq;
using NotifyPropertyWeaverMsBuildTask;
using NUnit.Framework;

namespace NotifyPropertyWeaverTests.IlGeneratedByDependencyReaderTests
{
    [TestFixture]
    public class WithUpperCaseUnderScoreFields
    {
        [Test]
        public void Run()
        {
            var typeDefinition = DefinitionFinder.FindType<Person>();
            var node = new TypeNode
            {
                TypeDefinition = typeDefinition,
                Mappings = MappingFinder.GetMappings(typeDefinition).ToList()
            };
            IlGeneratedByDependencyReader.Process(node);

            Assert.AreEqual("FullName", node.PropertyDependencies[0].ShouldAlsoNotifyFor.Name);
            Assert.AreEqual("GivenNames", node.PropertyDependencies[0].WhenPropertyIsSet.Name);
            Assert.AreEqual("FullName", node.PropertyDependencies[1].ShouldAlsoNotifyFor.Name);
            Assert.AreEqual("FamilyName", node.PropertyDependencies[1].WhenPropertyIsSet.Name);
        }

        public class Person
        {
            // ReSharper disable InconsistentNaming
            string _GivenNames;
            // ReSharper restore InconsistentNaming
            public string GivenNames
            {
                get { return _GivenNames; }
                set { _GivenNames = value; }
            }

            // ReSharper disable InconsistentNaming
            string _FamilyName;
            // ReSharper restore InconsistentNaming
            public string FamilyName
            {
                get { return _FamilyName; }
                set { _FamilyName = value; }
            }

            public string FullName
            {
                get
                {
                    return string.Format("{0} {1}", _GivenNames, _FamilyName);
                }
            }
        }
    }
}